#!/usr/bin/perl

use CGI qw(:standard);
use RPC::XML;
use RPC::XML::Client;
#use XML::Dumper;
use Data::Dumper;
use XML::Simple;


#my $dump = new XML::Dumper;
my $xml = new XML::Simple(KeyAttr=>'idUsuario');

$URL = "http://guest:guest\@localhost:8080/exist/xmlrpc";
print "connecting to $URL...\n";
$client = new RPC::XML::Client $URL;

# Output options
$options = RPC::XML::struct->new(
    'indent' => 'yes', 
    'encoding' => 'UTF-8');
    
# Peticion
$req = RPC::XML::request->new("getDocument", "/db/placeanddate/usuarios.xml", $options);
$resp = $client->send_request($req);
if($resp->is_fault) {
    die "An error occurred: " . $resp->string . "\n";
}

my $doc = $xml->XMLin($resp->value);

# Modificacion
$doc->{usuario}->{4}->{email}='jojo@gamil.comom';
##############

my $modif = $xml->XMLout($doc);

# Petición
$req = RPC::XML::request->new("parse",$modif,"/db/placeanddate/usuarios.xml",1);
$resp = $client->send_request($req);
if($resp->is_fault) {
    die "An error occurred: " . $resp->string . "\n";
}

# Comprobación
$req = RPC::XML::request->new("getDocument", "/db/placeanddate/usuarios.xml", $options);
$resp = $client->send_request($req);
if($resp->is_fault) {
    die "An error occurred: " . $resp->string . "\n";
}
